<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<script type="text/javascript">
	function validarQtdeCaracteres(valor, max){
		if(valor.length >= max) return false;
		else return true;
	}
</script>

<link rel="stylesheet" type="text/css" href="estilos.css" />

<f:view>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<f:loadBundle basename="entidade.mensagens" var="msg" />
	<title>Banca Alecrim</title>
	</head>
	<h:form >
		<body style="background-color: #aaaaaa">

		<jsp:include page="topoPagina.jsp" />

		<br />
		<br />
		<h:messages layout="table" styleClass="mensagemErro" errorClass="mensagemError" />
		
		<table width="60%" align="center" border="0" class="formulario">
			
			<caption>Buscar Clientes</caption>
			
			<tr>
				<th>Nome do Cliente:</th>
				<td><h:inputText value="#{buscaClientesMBean.usuario.nome}" size="50"></h:inputText></td>
			</tr>
			<tr>
				<th>CPF:</th>
				<td><h:inputText value="#{buscaClientesMBean.usuario.CPF}" size="11"
						onkeypress="return validarQtdeCaracteres(this.value, 11);" /></td>
			</tr>
			
			<tfoot>
				<tr>
					<td colspan="3"><h:commandButton type="submit"  value="Buscar"
						action="#{buscaClientesMBean.buscar}" ></h:commandButton></td>	
				</tr>
			</tfoot>
			
		</table>
		
		<br/><br/>
		
		<c:if test="${not empty buscaClientesMBean.listaUsuario}">
		<h:dataTable value="#{buscaClientesMBean.listaUsuario}" var="cliente"
				headerClass="headerClass" rowClasses="linhaPar,linhaImpar" styleClass="dataTableClass"
				columnClasses="colunaCNPJ,colunaNome">
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="CPF"></h:outputText>
					</f:facet>				
					<h:outputText value="#{cliente.CPF}"></h:outputText>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value="Nome"></h:outputText>
					</f:facet>				
					<h:outputText value="#{cliente.nome}"></h:outputText>
				</h:column>
				
				<h:column>
					<h:commandLink action="#{buscaClientesMBean.VisualizaCliente}">
						<h:graphicImage value="icones/view.gif" title="Visualizar Cliente" styleClass="img"/>
					</h:commandLink>
				</h:column>
				
				<h:column>
					<f:facet name="header">
						<h:outputText value=""></h:outputText>
					</f:facet>
					<h:commandLink action="#{buscaClientesMBean.RemoverCliente}" 
						onclick='return confirm("Deseja realmente remover o cliente?")'>
						<h:graphicImage value="icones/remove.gif" title="Remover Cliente" styleClass="img"/>
					</h:commandLink>
				</h:column>
				
		</h:dataTable>
		</c:if>
		
		<br/>

		</body>
	</h:form>
</f:view>
</html>